﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace ServiceOperater.Helpers
{
    public static class FileHelper
    {
        public static bool isDir(String path)
        {
            // https://stackoverflow.com/questions/439447/net-how-to-check-if-path-is-a-file-and-not-a-directory

            if (!Directory.Exists(path))
            {
                return false;
            }

            bool isDir = (File.GetAttributes(path) & FileAttributes.Directory)
                 == FileAttributes.Directory;

            return isDir;
        }

        public static bool isNotDir(String path)
        {
            return (!isDir(path));
        }

        // 打开所处的目录, 并选中该文件
        // https://stackoverflow.com/questions/13680415/how-to-open-explorer-with-a-specific-file-selected
        public static bool ExploreFile(string filePath)
        {
            if (!System.IO.File.Exists(filePath))
            {
                return false;
            }
            //Clean up file path so it can be navigated OK
            filePath = System.IO.Path.GetFullPath(filePath);
            System.Diagnostics.Process.Start("explorer.exe", string.Format("/select,\"{0}\"", filePath));
            return true;
        }
    }
}
